home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / WASTE Object Handlers 1.2.2.sit / WASTE Object Handlers 1.2.2 / Other Source / SendFinderOpen.c < prev    next >
Text File  |  1996-07-16  |  4KB  |  148 lines

  1. // File Object Handler Utilities for the WASTE Text Engine
  2. // Part of the WASTE Object Handler Library by Michael Kamprath, kamprath@kagi.com
  3. // maintenance by John C. Daub, hsoi@eden.com
  4. //
  5. // v1.2 28 March 1996,  Cleaned up the file with precompiler directives, removing potential
  6. //                        warning messages
  7.  
  8. #ifndef __ALIASES__
  9. #include <Aliases.h>
  10. #endif
  11.  
  12. #include "SendFinderOpen.h"
  13.  
  14. #define kFinderSig            'FNDR'
  15. #define kAEFinderEvents        'FNDR'
  16. #define kSystemType            'MACS'
  17.  
  18. #define    kAEOpenSelection    'sope'
  19. #define keySelection        'fsel'
  20.  
  21. OSErr SendFinderOpenAE(FSSpec *theDoc)
  22. {
  23. AppleEvent            aeEvent;
  24. AEDesc                myAddressDesc;
  25. AEDesc                aeDirDesc;
  26. AEDesc                listElem;
  27. AEDescList            fileList;
  28. FSSpec                dirSpec;
  29. AliasHandle            dirAlias;
  30. AliasHandle            fileAlias;
  31. ProcessSerialNumber    process;
  32. OSErr                myErr;
  33. OSType            FndrType = 'MACS';
  34.     
  35.     /*
  36.      * Get the psn of the Finder and create the target address for the AE
  37.      */
  38.     
  39.     if ( FindAProcess( kFinderSig, kSystemType, &process) )
  40.         return( procNotFound );
  41.  
  42.     myErr = AECreateDesc( typeProcessSerialNumber, (Ptr)&process, 
  43.                             sizeof(process), &myAddressDesc);
  44.     if (myErr) return(myErr);
  45.     
  46.     /*
  47.      * Create an empty Apple Event
  48.      */
  49.     
  50.     myErr = AECreateAppleEvent( kAEFinderEvents, kAEOpenSelection, &myAddressDesc,
  51.                                 kAutoGenerateReturnID, kAnyTransactionID, &aeEvent);
  52.     
  53.     if (myErr) return(myErr);
  54.     
  55.     /*
  56.      * Make and FSSpec for the parent folder and an alias of the file.
  57.      */
  58.     
  59.     FSMakeFSSpec( theDoc->vRefNum, theDoc->parID, 0L, &dirSpec);
  60.     NewAlias( nil, &dirSpec, &dirAlias);
  61.     NewAlias( nil, theDoc, &fileAlias);
  62.     
  63.     
  64.     /*
  65.      * Create the File list.
  66.      *
  67.      */
  68.     
  69.     HLockHi( (Handle)dirAlias);
  70.     AECreateDesc( typeAlias, (Ptr)*dirAlias, GetHandleSize( (Handle)dirAlias), &aeDirDesc);
  71.     HUnlock( (Handle)dirAlias);
  72.     DisposeHandle( (Handle)dirAlias);
  73.     
  74.     if ( (myErr=AEPutParamDesc(&aeEvent, keyDirectObject, &aeDirDesc)) == noErr )
  75.     {
  76.         AEDisposeDesc( &aeDirDesc );
  77.         
  78.         AECreateList(nil, 0, FALSE, &fileList);
  79.         HLockHi( (Handle)fileAlias);
  80.         myErr = AECreateDesc( typeAlias, (Ptr)*fileAlias, 
  81.                                     GetHandleSize( (Handle)fileAlias), &listElem);
  82.         HUnlock( (Handle)fileAlias);
  83.  
  84.         DisposeHandle( (Handle)fileAlias);
  85.     
  86.         myErr = AEPutDesc( &fileList, 0L, &listElem);
  87.         
  88.         if (myErr) return(myErr);
  89.         
  90.     }
  91.     if (myErr) return(myErr);
  92.     
  93.     AEDisposeDesc(&listElem);
  94.     
  95.     myErr = AEPutParamDesc(&aeEvent, keySelection, &fileList);
  96.     if (myErr) return(myErr);
  97.  
  98.     myErr = AEDisposeDesc( &fileList);
  99.     if (myErr) return(myErr);
  100.     
  101.     myErr = AESend( &aeEvent, 0L, kAENoReply+kAEAlwaysInteract+kAECanSwitchLayer,
  102.                     kAENormalPriority, kAEDefaultTimeout, 0L, 0L);¥
  103.                 
  104.     AEDisposeDesc(&aeEvent);
  105.     
  106.     return(myErr);
  107. }
  108.  
  109. /*
  110.  * Search though the current process list to find the given application. 
  111.  *
  112.  */
  113.  
  114. OSErr FindAProcess( OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN)
  115. {
  116. ProcessInfoRec            tempInfo;
  117. FSSpec                    procSpec;
  118. Str31                    processName;
  119. OSErr                    myErr = noErr;
  120.  
  121.     /*
  122.      * Start at begining of process list
  123.      */
  124.     
  125.     processSN->lowLongOfPSN = kNoProcess;
  126.     processSN->highLongOfPSN = kNoProcess;
  127.     
  128.     /*
  129.      * Init the process information record.
  130.      *
  131.      */
  132.     
  133.     tempInfo.processInfoLength = sizeof(ProcessInfoRec);
  134.     tempInfo.processName = (StringPtr)&processName;
  135.     tempInfo.processAppSpec = &procSpec;
  136.     
  137.     while ( (tempInfo.processSignature != creatorToFind || tempInfo.processType != typeToFind)
  138.                 || myErr != noErr)
  139.     {
  140.         myErr = GetNextProcess(processSN);
  141.         if (myErr == noErr)
  142.             GetProcessInformation( processSN, &tempInfo);
  143.     }
  144.         
  145.     return(myErr);
  146. }
  147.  
  148.